package 笔试题;

import java.util.Scanner;

/**
 * @author 帅小伙
 * @date 2022/1/2
 * @description
 */
public class Demo2022贝壳找房3 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        for (int i = 0; i < m; i++) {
            int n = scanner.nextInt();
            String str = scanner.next();
            char[] chars = str.toCharArray();
            int r=0;
            int res = 0;
            for (int j = 0; j < n; j++) {
                if(chars[j]==')'){
                    if(r==0){
                        res++;
                    }else{
                        r--;
                    }
                }else{
                    r++;
                }
            }
            System.out.println(res);
        }
    }
}
